
    TestCase
    (
        'ie.ondevice.objectkit.utility.runtime.RuntimeTestCase'
        
    ,   {
            testDeclare: function () 
            {
                var name= 'Id'
                ,   value= new Object
                ,   ns= 'x.y.z'
                ,   declared
                
                Runtime.declare(name, value);
                
                assertNotNull("Runtime declared the identifier in global scope", window[name]);
                assertSame('The value of the identifier is the same as declared', window[name], value);
                
                Runtime.declare(ns, value);
                
                assertNotNull('The x namespace was created', window.x);
                assertNotNull('The x.y namespace was created', x.y);
                assertNotNull('The x.y.z namespace was created', x.y.z);
                assertUndefined('The x.y.z.Id namespace does not exist yet', x.y.z.Id);
                
                Runtime.declare(name, value, x.y.z);
                assertNotNull('The x.y.z.Id object was declared', x.y.z.Id);

                // below throws a JSON.stringify cannot serialize cyclic structures error- WTF?
                // assertUndefined('Runtime.declare does not return any value', declared);
                
                declared= Runtime.declare(name, value, x.y.z); 
                assertSame('Runtime.declare returns a reference to the declared object', declared, value);
            }
            
        ,   testFind: function () 
            {
                var canonicalName= 'com.mock.Object'
                ,   noSuchName= 'org.mock.Object'
                ,   mock= {}
                ,   found
                
                Runtime.declare(canonicalName, mock);
                
                found= Runtime.find(canonicalName);
                assertTrue('The value exists', found.exists)
                assertSame('Runtime found the mock object in global scope', mock, found.value);
                
                found= Runtime.find('mock.Object', com);
                assertSame('Runtime found the mock object in com scope', mock, found.value);
                
                found= Runtime.find('com.mock');
                assertSame('Runtime found com.mock in global scope', com.mock, found.value);
                
                found= Runtime.find('Array.prototype.slice');
                assertSame('Runtime found Array.prototype.slice', [].slice, found.value);
                
                found= Runtime.find('charAt', String.prototype);
                assertSame('Runtime found String.prototype.charAt in String.prototype', ''.charAt, found.value);
                
                found= Runtime.find(noSuchName);
                assertFalse('Runtime correctly returned NOT_FOUND', found.exists);
                
                mock.property= null;
                
                found= Runtime.find('property', mock);
                assertTrue('Runtime found a namespace with a null value', found.exists);
                assertNull('The found value is null', found.value);
                
                mock.property= void(0);
                
                found= Runtime.find('property', mock);
                assertTrue('The property with an undefined value was found', found.exists)
                assertUndefined('Runtime found a namespace with an undefined value', found.value);
                
                delete mock.property;
                
                found= Runtime.find('property', mock);
                assertFalse('The deleted property was not found because it does not exist', found.exists);
                assertUndefined('Runtime returned NOT_FOUND as the object does not exist', found.value)
            }
            
        ,   testNamespace: function () 
            {
                var namespace= 'a.b.c'
                ,   globalScope= Runtime.getGlobal()
                ,   localScope= new Object
                ,   value= new String
                ,   declared
                
                
                declared= Runtime.namespace(namespace);
                assertNotNull('window.a was defined in global scope', window.a);
                assertNotNull('a.b was declared in global scope', a.b);
                assertNotNull('a.b.c was declared in global scope', a.b.c);
                
                assertSame('The returned value was the last node of the namespace', a.b.c, declared);
                
                Runtime.namespace('value', value, a.b.c);
                
                assertSame('The value was declared on global.a.b.c.value', a.b.c.value, value);
                
                Runtime.declare(namespace, value, localScope);
                assertSame('The value object was declared on localScope.a.b.c', localScope.a.b.c, value);
            }
            
        ,   testGetGlobal: function () 
            {
                assertSame('Runtime returned the global scope', window, Runtime.getGlobal());
            }
        }
    );
